package com.shuyuntu.proposal.entity;

import com.shuyuntu.proposal.enums.EMessageType;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by limeng on 16-4-26.
 */
@Entity
@Table(name = "message")
public class Message {
    /**
     * id 自增
     */
    private Integer id;

    /**
     * 通知的内容
     */
    private String content;

    /**
     * 发送者（此处应为管理员，暂时用教师代表代替）
     */
    private Delegate sender;

    /**
     * 接收者
     */
    private Delegate receiver;

    /**
     * 发送时间
     */
    private Date sendTime;

    /**
     * 消息类型（通知/动态）
     */
    private EMessageType type;

    /**
     * 是否是未读信息
     */
    private boolean unread;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(length = 255, nullable = false)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @ManyToOne
    @JoinColumn(name = "sender_id")
    public Delegate getSender() {
        return sender;
    }

    public void setSender(Delegate sender) {
        this.sender = sender;
    }

    @ManyToOne
    @JoinColumn(name = "receiver_id", nullable = false)
    public Delegate getReceiver() {
        return receiver;
    }

    public void setReceiver(Delegate receiver) {
        this.receiver = receiver;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "send_time", nullable = false)
    public Date getSendTime() {
        return sendTime;
    }

    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }

    @Enumerated(EnumType.ORDINAL)
    @Column(nullable = false)
    public EMessageType getType() {
        return type;
    }

    public void setType(EMessageType type) {
        this.type = type;
    }

    @Column(nullable = false, columnDefinition = "bit(1) default 1")
    public boolean isUnread() {
        return unread;
    }

    public void setUnread(boolean unread) {
        this.unread = unread;
    }
}
